﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data;
public partial class Admin_InsertUsers : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Page.SetFocus(Txname.Text);
    }

    protected void BtReg_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("name");
        dt.Columns.Add("family");
        dt.Columns.Add("address");
        dt.Columns.Add("phone");
        dt.Columns.Add("email");
        dt.Columns.Add("Mobile");
        dt.Columns.Add("Username");
        
     if (Membership.GetUser(TxUser.Text) == null)
        {
           
         if (RlistUser.SelectedValue == "" ) {
         
                Lbl.Visible = true;
                Lbl.Text = "لطفا سطح دسترسی را مشخص کنید";
                LblStatus.Visible = false; 
         } 
         else {

             if (RlistUser.SelectedItem.Value=="Mng"){
                Membership.CreateUser(TxUser.Text.ToString(), TxConf.Text.ToString());
                Roles.AddUserToRole(TxUser.Text, "AdminExpert");
             }
            else if (RlistUser.SelectedItem.Value =="Fin"){
            Membership.CreateUser(TxUser.Text.ToString(), TxPass.Text.ToString());
                Roles.AddUserToRole(TxUser.Text, "Finance");
            }
            else if(RlistUser.SelectedItem.Value =="Secr"){
             Membership.CreateUser(TxUser.Text.ToString(), TxPass.Text.ToString());
                Roles.AddUserToRole(TxUser.Text, "Secret");
            }
             
                ProfileCommon p = Profile.GetProfile(TxUser.Text);
                p.Common.FirstName = Txname.Text;
                p.Common.LastName = Txfamily.Text;
                p.Common.Address = TxAddre.Text;
                p.Common.Email = TxEmai.Text;
                p.Common.Phone = TxTele.Text;
                p.Common.Mobile = TxMob.Text;
                p.Common.username = TxUser.Text;
                p.Common.Status = "On";
                p.Common.CategoryID = 1;
                DataRow dr;
                dr = dt.NewRow();
                dr["name"] = Txname.Text;
                dr["Username"] = TxUser.Text;
                dr["family"] = Txfamily.Text;
                dr["address"] = TxAddre.Text;
                dr["phone"] = TxTele.Text;
                dr["email"] = TxEmai.Text;
                dr["Mobile"] = TxMob.Text;
                p.Save();
                dt.Rows.Add(dr);
                LblSuccess.Text = "نام کاربری با موفقیت اضافه شد";
                Txname.Text = "";
                Txfamily.Text = "";
                TxMob.Text = "";
                TxEmai.Text = "";
                TxTele.Text = "";
                TxMob.Text = "";
                TxTele.Text = "";
                TxAddre.Text = "";
                TxUser.Text = "";
                LblStatus.Visible = false;
                Lbl.Visible = false;
                GridView1.DataSource = dt;
                GridView1.DataBind();
                PlUserData.Visible = true;
         }
          
              

     }
        
       
        else
        {
            LblStatus.Visible = true;  
         LblStatus.Text = "نام کاربری جدید انتخاب کنید";
              
     }
                
    }


      
}

       
